package com.tqy.docms.service.impl;

import com.tqy.docms.dao.XwMapper;
import com.tqy.docms.entity.Xw;
import com.tqy.docms.service.XwService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * @title: XwServiceImpl
 * @projectName: tqygw
 * @description: 新闻 服务层
 * @author: yuzf
 * @date: 2019/6/27 15:05
 */
@Service
public class XwServiceImpl implements XwService {

    private static final Logger LOG = LoggerFactory.getLogger(XwServiceImpl.class);

    @Autowired
    private XwMapper xwMapper;

    @Override
    public int addXw(Xw xw) {
        UUID uuid = UUID.randomUUID();
        xw.setNm(uuid.toString().replace("-", ""));
        int result = xwMapper.addXw(xw);
        if(result == 1) {
            LOG.info("插入一条数据至TQY_XW");
        }else{
            LOG.error("插入数据至TQY_XW失败");
        }
        return result;
    }

    @Override
    public int delXw(String nm) {
        int result = xwMapper.delXw(nm);
        if(result>0) {
            LOG.info("成功删除TQY_XW表中"+ result +"条数据");
        }else {
            LOG.error("删除TQY_XW表中数据失败");
        }
        return result;
    }

    @Override
    public int editXw(Xw xw) {
        int result = xwMapper.editXw(xw);
        if(result>0) {
            LOG.info("成功修改TQY_XW表中"+ result +"条数据");
        }else {
            LOG.error("修改TQY_XW表中数据失败");
        }
        return result;
    }

    @Override
    public List<Xw> getallXw() {
        List<Xw> xws = xwMapper.getallXw();
        return xws;
    }

    @Override
    public Xw getoneXw(String nm) {
        Xw xw = xwMapper.getoneXw(nm);
        return xw;
    }

    @Override
    public List<Xw> selectXw(Xw xw) {
        List<Xw> xws = xwMapper.selectXw(xw);
        return xws;
    }
}
